package com.naicheng.ivote.views;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.naicheng.ivote.R;
import com.naicheng.ivote.engin.BaseActivity;
import com.naicheng.ivote.volley.Request;
import com.naicheng.ivote.volley.RequestQueue;
import com.naicheng.ivote.volley.Response.ErrorListener;
import com.naicheng.ivote.volley.Response.Listener;
import com.naicheng.ivote.volley.VolleyError;
import com.naicheng.ivote.volley.toolbox.JsonObjectRequest;
import com.naicheng.ivote.volley.toolbox.Volley;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * 接口测试类
 * @author Administrator
 *
 */


public class TestActivity extends BaseActivity {
	
	TestActivity CTTA=TestActivity.this;
	private TextView main_tv;
	private Button main_but;
	
	private RequestQueue rq;
	private JsonObjectRequest jor;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_main);
		
//		main_but=(Button) findViewById(R.id.main_but);
//		main_tv=(TextView) findViewById(R.id.main_tv);
//		main_tv.setText("是什么？");
		
//		network();
		
//		main_but.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
////				rq.add(jor);
//				
//				
//			}
//		});
		
		getData();
		
		
	}
	
	
	public void getData(){
		Listener<JSONObject> resli=new Listener<JSONObject>() {

			@Override
			public void onResponse(JSONObject response) {
				System.out.println("response:"+response.toString());
				//main_tv.setText(response.toString());
			}
		};
		getDataFromServer("register", null, resli, this);
	}

	public void network(){
//		String url="http://vote.irongcheng.com/api";
		String url="http://vote.irongcheng.com/api/";
		rq=Volley.newRequestQueue(CTTA);
		
		Map<String, String> params = new HashMap<String, String>();
		params.put("requestname", "test");
		params.put("requestpassword", "123321");
		params.put("requesttime", "2014-04-01 16:46:13");
		params.put("requestcommand", "register");
		JSONObject jsonRequest=new JSONObject(params);
		Listener<JSONObject> resli=new Listener<JSONObject>() {

			@Override
			public void onResponse(JSONObject response) {
				System.out.println("response:"+response.toString());
				main_tv.setText(response.toString());
			}
		};
		ErrorListener errorlistener = new ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError error) {
				System.out.println("error->"+error.getMessage());
			}
		};
		
		
		jor=new JsonObjectRequest(Request.Method.POST, url, jsonRequest, resli, errorlistener);
	}
	

}
